
<html><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta content="text/javascript" http-equiv="content-script-type">
<title>system.text.UTF</title>
<link rel="stylesheet" type="text/css" href="candydoc/style.css">
<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="candydoc/ie56hack.css"><![endif]-->
<script language="JavaScript" src="candydoc/util.js" type="text/javascript"></script>
<script language="JavaScript" src="candydoc/tree.js" type="text/javascript"></script>
<script language="JavaScript" src="candydoc/explorer.js" type="text/javascript"></script>
</head><body>
<div id="tabarea"></div><div id="explorerclient"></div>
<div id="content"><script>explorer.initialize("system.text.UTF");</script>
	<table class="content">
		<tr><td id="docbody"><h1>system.text.UTF</h1><!-- Generated by Ddoc from F:\MyWork\phoenix\source\system\text\UTF.d -->
<b>License:</b><br>
BSD style: 
<br><br>
<b>Version:</b><br>
Initial release: Oct 2004
             Modified by Lucifer in May 2008
<br><br>
<b>Authors:</b><br>
Kris, Lucifer(lucifer1982@yeah.net)
<br><br>

 Fast Unicode transcoders. These are particularly sensitive to
 minor changes on 32bit x86 devices, because the register set of
 those devices is so small. Beware of subtle changes which might
 extend the execution-period by as much as 200%. Because of this,
 three of the six transcoders might read past the end of input by
 one, two, or three bytes before arresting themselves. Note that
 support for streaming adds a 15% overhead to the dchar =&gt; char
 conversion, but has little effect on the others.
<br><br>

 These routines were tuned on an Intel P4; other devices may work
 more efficiently with a slightly different approach, though this
 is likely to be reasonably optimal on AMD x86 CPUs also. These
 algorithms would benefit significantly from those extra AMD64
 registers. On a 3GHz P4, the dchar/char conversions take around
 2500ns to process an array of 1000 ASCII elements. Invoking the
 memory manager doubles that period, and quadruples the time for
 arrays of 100 elements. Memory allocation can slow down notably
 in a multi-threaded environment, so avoid that where possible.
<br><br>

 Surrogate-pairs are dealt with in a non-optimal fashion when
 transcoding between UTF16 and UTF8. Such cases are considered
 to be boundary-conditions for this module.
<br><br>

 There are three common cases where the input may be incomplete,
 including each 'widening' case of UTF8 =&gt; UTF16, UTF8 =&gt; UTF32,
 and UTF16 =&gt; UTF32. An edge-case is UTF16 =&gt; UTF8, if surrogate
 pairs are present. Such cases will throw an exception, unless
 streaming-mode is enabled ~ in the latter mode, an additional
 integer is returned indicating how many elements of the input
 have been consumed. In all cases, a correct slice of the output
 is returned.
<br><br>

 For details on Unicode processing see:
 <ul><a href="http://www.utf-8.com/">http://www.utf-8.com/</a></ul>
 <ul><a href="http://www.hackcraft.net/xmlUnicode/">http://www.hackcraft.net/xmlUnicode/</a></ul>
 <ul><a href="http://www.azillionmonkeys.com/qed/unicode.html/">http://www.azillionmonkeys.com/qed/unicode.html/</a></ul>
 <ul><a href="http://icu.sourceforge.net/docs/papers/forms_of_unicode/">http://icu.sourceforge.net/docs/papers/forms_of_unicode/</a></ul>
<br><br>

 
<br><br>

 Unicode编码转换模块
 
<br><br>


<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl">class 
<span class="currsymbol">UTFException</span>
<script>explorer.outline.addDecl('UTFException');</script>

: system.Exception.BaseException;
</span></dt>
<script>explorer.outline.writeEnabled = false;</script>


<dd>Exception class that is thrown upon any errors.
 
<br><br>


<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl">size_t 
<span class="currsymbol">index</span>
<script>explorer.outline.addDecl('index');</script>

;
</span></dt>
<script>explorer.outline.writeEnabled = false;</script>


<dd>
<span class="currsymbol">index</span>
<script>explorer.outline.addDecl('index');</script>

 in string of where error occurred.
	 
<br><br>

</dd>
</dl>
<script>explorer.outline.decSymbolLevel();</script>


</dd>

<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl">string 
<span class="currsymbol">toUTF8</span>
<script>explorer.outline.addDecl('toUTF8');</script>

(const(wchar)[] <span class="funcparam">input</span>, char[] <span class="funcparam">output</span> = null, uint* <span class="funcparam">ate</span> = null);
</span></dt>
<script>explorer.outline.writeEnabled = false;</script>


<dd>Encode UTF8 up to a maximum of 4 bytes long (five &amp; six byte
 variations are not supported).
<br><br>
If the <span class="funcparam">output</span> is provided off the stack, it should be large
 enough to encompass the entire transcoding; failing to do
 so will cause the <span class="funcparam">output</span> to be moved onto the heap instead.
<br><br>

 Returns a slice of the <span class="funcparam">output</span> buffer, corresponding to the
 converted characters. For optimum performance, the returned
 buffer should be specified as '<span class="funcparam">output</span>' on subsequent calls.
<br><br>

 For example:
<pre class="d_code"> <font color=blue>char</font>[] <i>output</i>;

 <font color=blue>char</font>[] result = <u>toUTF8</u> (<i>input</i>, <i>output</i>);

 <font color=green>// reset output after a realloc
</font> <font color=blue>if</font> (result.length &gt; <i>output</i>.length)
     <i>output</i> = result;
</pre>
 
<br><br>

</dd>

<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl">wstring 
<span class="currsymbol">toUTF16</span>
<script>explorer.outline.addDecl('toUTF16');</script>

(const(char)[] <span class="funcparam">input</span>, wchar[] <span class="funcparam">output</span> = null, uint* <span class="funcparam">ate</span> = null);
</span></dt>
<script>explorer.outline.writeEnabled = false;</script>


<dd>Decode UTF8 produced by the above toUTF8() method.
<br><br>
If the <span class="funcparam">output</span> is provided off the stack, it should be large
 enough to encompass the entire transcoding; failing to do
 so will cause the <span class="funcparam">output</span> to be moved onto the heap instead.
<br><br>

 Returns a slice of the <span class="funcparam">output</span> buffer, corresponding to the
 converted characters. For optimum performance, the returned
 buffer should be specified as '<span class="funcparam">output</span>' on subsequent calls.
 
<br><br>

</dd>

<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl">string 
<span class="currsymbol">toUTF8</span>
<script>explorer.outline.addDecl('toUTF8');</script>

(const(dchar)[] <span class="funcparam">input</span>, char[] <span class="funcparam">output</span> = null, uint* <span class="funcparam">ate</span> = null);
</span></dt>
<script>explorer.outline.writeEnabled = false;</script>


<dd>Encode UTF8 up to a maximum of 4 bytes long (five &amp; six
 byte variations are not supported). Throws an exception
 where the <span class="funcparam">input</span> dchar is greater than 0x10ffff.
<br><br>
If the <span class="funcparam">output</span> is provided off the stack, it should be large
 enough to encompass the entire transcoding; failing to do
 so will cause the <span class="funcparam">output</span> to be moved onto the heap instead.
<br><br>

 Returns a slice of the <span class="funcparam">output</span> buffer, corresponding to the
 converted characters. For optimum performance, the returned
 buffer should be specified as '<span class="funcparam">output</span>' on subsequent calls.
 
<br><br>

</dd>

<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl">dstring 
<span class="currsymbol">toUTF32</span>
<script>explorer.outline.addDecl('toUTF32');</script>

(const(char)[] <span class="funcparam">input</span>, dchar[] <span class="funcparam">output</span> = null, uint* <span class="funcparam">ate</span> = null);
</span></dt>
<script>explorer.outline.writeEnabled = false;</script>


<dd>Decode UTF8 produced by the above toUTF8() method.
<br><br>
If the <span class="funcparam">output</span> is provided off the stack, it should be large
 enough to encompass the entire transcoding; failing to do
 so will cause the <span class="funcparam">output</span> to be moved onto the heap instead.
<br><br>

 Returns a slice of the <span class="funcparam">output</span> buffer, corresponding to the
 converted characters. For optimum performance, the returned
 buffer should be specified as '<span class="funcparam">output</span>' on subsequent calls.
 
<br><br>

</dd>

<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl">wstring 
<span class="currsymbol">toUTF16</span>
<script>explorer.outline.addDecl('toUTF16');</script>

(const(dchar)[] <span class="funcparam">input</span>, wchar[] <span class="funcparam">output</span> = null, uint* <span class="funcparam">ate</span> = null);
</span></dt>
<script>explorer.outline.writeEnabled = false;</script>


<dd>Encode UTF16 up to a maximum of 2 bytes long. Throws an exception
 where the <span class="funcparam">input</span> dchar is greater than 0x10ffff.
<br><br>
If the <span class="funcparam">output</span> is provided off the stack, it should be large
 enough to encompass the entire transcoding; failing to do
 so will cause the <span class="funcparam">output</span> to be moved onto the heap instead.
<br><br>

 Returns a slice of the <span class="funcparam">output</span> buffer, corresponding to the
 converted characters. For optimum performance, the returned
 buffer should be specified as '<span class="funcparam">output</span>' on subsequent calls.
 
<br><br>

</dd>

<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl">dstring 
<span class="currsymbol">toUTF32</span>
<script>explorer.outline.addDecl('toUTF32');</script>

(const(wchar)[] <span class="funcparam">input</span>, dchar[] <span class="funcparam">output</span> = null, uint* <span class="funcparam">ate</span> = null);
</span></dt>
<script>explorer.outline.writeEnabled = false;</script>


<dd>Decode UTF16 produced by the above toUTF16() method.
<br><br>
If the <span class="funcparam">output</span> is provided off the stack, it should be large
 enough to encompass the entire transcoding; failing to do
 so will cause the <span class="funcparam">output</span> to be moved onto the heap instead.
<br><br>

 Returns a slice of the <span class="funcparam">output</span> buffer, corresponding to the
 converted characters. For optimum performance, the returned
 buffer should be specified as '<span class="funcparam">output</span>' on subsequent calls.
 
<br><br>

</dd>
</dl>
<script>explorer.outline.decSymbolLevel();</script>


</td></tr>
		<tr><td id="docfooter">
			Page was generated with
			<img src="candydoc/img/candydoc.gif" style="vertical-align:middle; position:relative; top:-1px">
			on Sat Nov 29 22:33:13 2008

		</td></tr>
	</table>
</div>
<script>
	explorer.packageExplorer.addModule("platform.PAL");
	explorer.packageExplorer.addModule("platform.windows.Core");
	explorer.packageExplorer.addModule("platform.linux.Core");
	explorer.packageExplorer.addModule("system.Array");
	explorer.packageExplorer.addModule("system.BitArray");
	explorer.packageExplorer.addModule("system.Environment");
	explorer.packageExplorer.addModule("system.Event");
	explorer.packageExplorer.addModule("system.Exception");
	explorer.packageExplorer.addModule("system.Hash");
	explorer.packageExplorer.addModule("system.IntPtr");
	explorer.packageExplorer.addModule("system.Random");
	explorer.packageExplorer.addModule("system.Traits");
	explorer.packageExplorer.addModule("system.TypeTuple");
	explorer.packageExplorer.addModule("system.math.IEEE");
	explorer.packageExplorer.addModule("system.math.Math");
	explorer.packageExplorer.addModule("system.runtime.c.complex");
	explorer.packageExplorer.addModule("system.runtime.c.config");
	explorer.packageExplorer.addModule("system.runtime.c.ctype");
	explorer.packageExplorer.addModule("system.runtime.c.errno");
	explorer.packageExplorer.addModule("system.runtime.c.fenv");
	explorer.packageExplorer.addModule("system.runtime.c.inttypes");
	explorer.packageExplorer.addModule("system.runtime.c.limits");
	explorer.packageExplorer.addModule("system.runtime.c.locale");
	explorer.packageExplorer.addModule("system.runtime.c.math");
	explorer.packageExplorer.addModule("system.runtime.c.signal");
	explorer.packageExplorer.addModule("system.runtime.c.stdarg");
	explorer.packageExplorer.addModule("system.runtime.c.stddef");
	explorer.packageExplorer.addModule("system.runtime.c.stdint");
	explorer.packageExplorer.addModule("system.runtime.c.stdio");
	explorer.packageExplorer.addModule("system.runtime.c.stdlib");
	explorer.packageExplorer.addModule("system.runtime.c.string");
	explorer.packageExplorer.addModule("system.runtime.c.time");
	explorer.packageExplorer.addModule("system.runtime.c.wctype");
	explorer.packageExplorer.addModule("system.text.UTF");
	explorer.packageExplorer.addModule("system.threading.Atomic");
	explorer.packageExplorer.addModule("system.threading.ThreadUtility");
	explorer.packageExplorer.addModule("system.threading.synchronization.SpinWait");
	explorer.packageExplorer.addModule("system.collections.ArrayList");
	explorer.packageExplorer.addModule("system.collections.Comparer");
	explorer.packageExplorer.addModule("system.collections.Deque");
	explorer.packageExplorer.addModule("system.collections.EqualityComparer");
	explorer.packageExplorer.addModule("system.collections.Exception");
	explorer.packageExplorer.addModule("system.collections.HashMap");
	explorer.packageExplorer.addModule("system.collections.HashSet");
	explorer.packageExplorer.addModule("system.collections.ICollection");
	explorer.packageExplorer.addModule("system.collections.IComparer");
	explorer.packageExplorer.addModule("system.collections.IDeque");
	explorer.packageExplorer.addModule("system.collections.IEnumerable");
	explorer.packageExplorer.addModule("system.collections.IEnumerator");
	explorer.packageExplorer.addModule("system.collections.IEqualityComparer");
	explorer.packageExplorer.addModule("system.collections.IList");
	explorer.packageExplorer.addModule("system.collections.IMap");
	explorer.packageExplorer.addModule("system.collections.IQueue");
	explorer.packageExplorer.addModule("system.collections.LinkedList");
	explorer.packageExplorer.addModule("system.collections.Pair");
	explorer.packageExplorer.addModule("system.collections.PrimeHelper");
	explorer.packageExplorer.addModule("system.collections.PriorityQueue");
	explorer.packageExplorer.addModule("system.collections.Queue");
	explorer.packageExplorer.addModule("system.collections.RBTree");
	explorer.packageExplorer.addModule("system.collections.Stack");
	explorer.packageExplorer.addModule("system.collections.TreeMap");
	explorer.packageExplorer.addModule("system.collections.TreeSet");
	explorer.packageExplorer.addModule("system.collections.objectmodel.ListCollection");
	explorer.packageExplorer.addModule("system.collections.objectmodel.ReadOnlyListCollection");</script>
</body></html>


